home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / DroneZone / DZMain.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  3.4 KB  |  175 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        DZMain.c
  3.  *
  4.  *    Contents:    Main entry point, main loop, initialize and exit code
  5.  *
  6.  *    Copyright © 1996 Apple Computer, Inc.
  7.  */
  8.  
  9. #include <Dialogs.h>
  10. #include <Fonts.h>
  11. #include <Memory.h>
  12. #include <QuickDraw.h>
  13. #include <Types.h>
  14. #include <Windows.h>
  15.  
  16. #include <QD3D.h>
  17.  
  18. #include "DZDisplay.h"
  19. #include "DZDrone.h"
  20. #include "DZEvents.h"
  21. #include "DZGame.h"
  22. #include "DZInput.h"
  23. #include "DZMain.h"
  24. #include "DZMenu.h"
  25. #include "DZSound.h"
  26. #include "DZSpace.h"
  27.  
  28.  
  29. #ifdef APP_LOADS_SOUND_COMPONENT
  30.     #include "S3Private.h"
  31. #endif
  32.  
  33. void main(
  34.     void);
  35.  
  36. static void Init(
  37.     void);
  38.  
  39. static void Exit(
  40.     void);
  41.  
  42.  
  43. static Boolean gAlive = false;
  44.  
  45.  
  46.  
  47. /* =============================================================================
  48.  *        main
  49.  *
  50.  *    Initializes, processes events, does the idle-time stuff, and exits.
  51.  * ========================================================================== */
  52. void main(
  53.     void)
  54. {
  55.     Init();
  56.     
  57.     while (gAlive)
  58.     {
  59.         Events_Process();
  60.         
  61.         if (gAlive && Display_IsActive() && Game_GetState() == kGameState_Playing)
  62.         {
  63.             Game_Process();
  64.             Display_DrawContents();
  65.         }
  66.     }
  67.     
  68.     Exit();
  69. }
  70.  
  71.  
  72. /* =============================================================================
  73.  *        Main_LastRoundup (external)
  74.  *
  75.  *    Requests the main event loop to gracefully exit.
  76.  * ========================================================================== */
  77. void Main_LastRoundup(
  78.     void)
  79. {
  80.     gAlive = false;
  81. }
  82.  
  83.  
  84. /* =============================================================================
  85.  *        Init (internal)
  86.  *
  87.  *    Initialization of toolbox and our stuff.
  88.  * ========================================================================== */
  89. void Init(
  90.     void)
  91. {
  92.     // Initialize the toolbox
  93.      MaxApplZone();
  94.     MoreMasters();
  95.     
  96.     InitGraf(&qd.thePort);
  97.     InitFonts();
  98.     InitWindows();
  99.     InitDialogs(NULL);
  100.     InitCursor();
  101.     InitMenus();
  102.     TEInit();
  103.     
  104.     qd.randSeed = TickCount();
  105.     
  106.     // Initialize QD3D
  107.     Q3Initialize();
  108.     
  109.     // Should we load S3Localization?
  110.     #ifdef APP_LOADS_SOUND_COMPONENT
  111.     {
  112.         ComponentDescription    filterDesc;
  113.         Handle                    filterNameHdl, infoHdl;
  114.         
  115.         // Register (or find) our components
  116. #ifdef REAL_3D_INSTALL
  117.         filterDesc.componentType            = kSoundEffectsType;
  118. #else
  119.         filterDesc.componentType            = 'sdec';
  120. #endif
  121.         filterDesc.componentSubType            = kSSpLocalizationSubType;
  122.         filterDesc.componentManufacturer    = kAppleManufacturer;
  123.         filterDesc.componentFlags            = 0L;
  124.         filterDesc.componentFlagsMask        = 0L;
  125.         
  126.         filterNameHdl = NewHandle (sizeof (Str255));
  127.         BlockMove ((Ptr)"\pS3Localization", (Ptr)(*filterNameHdl), sizeof (Str255));
  128.  
  129.         infoHdl = NewHandle (sizeof (Str255));
  130.         BlockMove ((Ptr)"\pThis component provides 3D Audio.", (Ptr)(*infoHdl), sizeof (Str255));
  131.         
  132.         // Register the Filter component
  133.         RegisterComponent (&filterDesc, NewComponentRoutineProc(SoundComponentProc), kRegisterGlobally,
  134.             filterNameHdl, infoHdl, nil);
  135.     }
  136.     #endif
  137.     
  138.     // Initialize our modules
  139.     Menu_Init();
  140.     Sound_Init();
  141.     Events_Init();
  142.     Display_Init();
  143.     Drone_Init();
  144.     Space_Init();
  145.     Input_Init();
  146.     Game_Init();
  147.     
  148.     // We're off...
  149.     gAlive = true;
  150. }
  151.  
  152.  
  153. /* =============================================================================
  154.  *        Exit (internal)
  155.  *
  156.  *    Cleans up before exit.
  157.  * ========================================================================== */
  158. void Exit(
  159.     void)
  160. {
  161.     // Exit our modules
  162.     Game_Exit();
  163.     Input_Exit();
  164.     Space_Exit();
  165.     Drone_Exit();
  166.     Display_Exit();
  167.     Events_Exit();
  168.     Sound_Exit();
  169.     Menu_Exit();
  170.     
  171.     // Exit QD3D
  172.     Q3Exit();
  173. }
  174.  
  175.